//
//  XJAddNewAddressFooterView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/21.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJAddNewAddressFooterView.h"
@interface XJAddNewAddressFooterView()

//@property(nonatomic, strong) UILabel *defaultAddressLabel; //设置默认地址
//@property(nonatomic, strong) UIButton *selectButton; // 选中button
@property(nonatomic, strong) UIView *lineTopView; // 上面的线条
@property(nonatomic, strong) UIView *lineBottomView; // 下面的线条
@property(nonatomic, strong) UIButton *sureButton;
@end

@implementation XJAddNewAddressFooterView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    [self addSubview:self.lineTopView];
    [self addSubview:self.lineBottomView];
    
//    [self addSubview:self.defaultAddressLabel];
//    [self addSubview:self.selectButton];
    [self addSubview:self.sureButton];
}

#pragma mark - 二 lazy
//- (UILabel *)defaultAddressLabel {
//    if (!_defaultAddressLabel) {
//        _defaultAddressLabel = [[UILabel alloc] init];
//        _defaultAddressLabel.text = @"设为默认地址";
//    }
//    return _defaultAddressLabel;
//}

//- (UIButton *)selectButton {
//    if (!_selectButton) {
//
//        _selectButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
//        [_selectButton setImage:[UIImage imageNamed:@"selected_off"] forState:(UIControlStateNormal)];
//        [_selectButton setImage:[UIImage imageNamed:@"selected_on"] forState:(UIControlStateSelected)];
//        [_selectButton addTarget:self action:@selector(clickSelectButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
//    }
//    return _selectButton;
//}

- (UIView *)lineTopView {
    if (!_lineTopView) {
        _lineTopView = [[UIView alloc] init];
        _lineTopView.backgroundColor = XJCOLOR_RGB(199, 199, 204);
    }
    return _lineTopView;
}

- (UIView *)lineBottomView {
    if (!_lineBottomView) {
        _lineBottomView = [[UIView alloc] init];
        _lineBottomView.backgroundColor = XJCOLOR_RGB(199, 199, 204);
    }
    return _lineBottomView;
}
- (UIButton *)sureButton {
    if (!_sureButton) {
        _sureButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_sureButton setTitle:@"确认" forState:(UIControlStateNormal)];
        [_sureButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        [_sureButton setTitleColor:[UIColor lightGrayColor] forState:(UIControlStateHighlighted)];
        [_sureButton setBackgroundColor:XJCOLOR_RGB(255, 216, 67)];
        
        _sureButton.layer.masksToBounds = YES;
        _sureButton.layer.cornerRadius = 10;
        
        [_sureButton addTarget:self action:@selector(clickSureButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _sureButton;
}
#pragma mark - 三 layout
- (void)layoutSubviews {
    [super layoutSubviews];

    [self.lineTopView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.equalTo(self);
        make.left.equalTo(self.mas_left).offset(15);
        make.height.mas_equalTo(@0.5);
    }];
    
//    [self.defaultAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.mas_left).offset(15);
//        make.size.mas_equalTo(CGSizeMake(150, 44));
//        make.top.equalTo(self.mas_top).offset(10);
//    }];
    
//    [self.selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self.mas_top).offset(10);
//        make.right.equalTo(self.mas_right).offset(-15);
//        make.size.mas_equalTo(CGSizeMake(30, 30));
//    }];
    
    
//    [self.lineBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.defaultAddressLabel.mas_bottom);
//        make.left.right.equalTo(self.mas_left).offset(15);
//        make.height.mas_equalTo(@0.5);
//    }];
    
    [self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineBottomView.mas_bottom).offset(10);
        make.centerX.equalTo(self.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(280, 40));
    }];

}

#pragma mark - 四 事件回调
//- (void)clickSelectButtonAction {
//    self.selectButton.selected = !self.selectButton.isSelected;
//    XJLog(@"");
//}

- (void)clickSureButtonAction {
    XJLog(@"");
    
    if (self.addNewAddressFooterViewSureButtonBlock) {
        self.addNewAddressFooterViewSureButtonBlock();
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
